import React, { useReducer } from "react";

const SItemContext = React.createContext();

const dataReducer = (state, action) => {
  switch (action.type) {
    case "add_data":
      return state;
    case "edit_data":
      return state;
    default:
      return state;
  }
};

let initData = [
  {
    basePlate: {
      name: "不锈钢板",
      density: [1.68, 0],
      model: [2.0, 3.0, 0.3, 0],
    },
    shroudPlate: {
      name: "7070铝板",
      density: [1.68, 0],
      model: [2.0, 3.0, 0.3, 0],
    },
    unitPriceByArea: [26350, 0],
    unitPriceByWeight: [19000, 1],
  },
  {
    basePlate: {
      name: "钢板QF987",
      density: [1.68, 0],
      model: [2.0, 3.0, 0.3, 0],
    },
    shroudPlate: {
      name: "铝板Q87",
      density: [1.68, 0],
      model: [2.0, 3.0, 0.3, 0],
    },
    unitPriceByArea: [13450, 0],
    unitPriceByWeight: [19000, 1],
  },
];

export const SItemProvider = ({ children }) => {
  const [SItemData, dispatch] = useReducer(dataReducer, initData);
  // console.log("initData-", SItemContext);

  const addData = () => {
    dispatch({ type: "add_data" });
  };

  const editData = () => {
    dispatch({
      type: "edit_data",
    });
  };

  return (
    <SItemContext.Provider value={{ SItemData: SItemData, addData, editData }}>
      {children}
    </SItemContext.Provider>
  );
};

export default SItemContext;
